package gui;

import gui.popupmenu.AlbumPopupMenu;
import gui.popupmenu.RootAlbumPopupMenu;
import gui.treenode.AlbumTreeNode;
import gui.treenode.RootAlbumTreeNode;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author SUCCESS\quannguyen
 */
public class MyTree extends JTree {

    public MyTree() {
        this.addMouseListener(new TreeMouseAdapter());
    }
}

class TreeMouseAdapter extends MouseAdapter {

    @Override
    public void mousePressed(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON3) {
            JTree jTree = (JTree) e.getComponent();

            DefaultMutableTreeNode node =
                    (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
            JPopupMenu menu;
            if (node instanceof RootAlbumTreeNode) {
                menu = new RootAlbumPopupMenu();
            } else if (node instanceof AlbumTreeNode) {
                menu = new AlbumPopupMenu();
            } else {
                return;
            }
            menu.show(e.getComponent(), e.getX(), e.getY());
        }
    }
}